<template>
  <view class="card_xingzuo" v-if="starsigndata.fortune.all">
    <view class="box">
      <view class="card flex-align">
        <image :src="imgUrl" mode="scaleToFill" />
        <view class="card-r">
          <view class="txt flex-align">
            <text>{{ starsigndata.title }}{{ starsigndata.type }}</text>
            <view> {{ starsigndata.time }} </view>
          </view>
          <view class="exponent">
            <view class=""
              >综合运势:
              <u-rate
                :count="count"
                :modelValue="starsigndata.fortune.all"
                readonly
                active-color="#ffca2a"
              ></u-rate
            ></view>
            <view class=""
              >爱情运势:
              <u-rate
                :count="count"
                :modelValue="starsigndata.fortune.love"
                readonly
                active-color="#ffca2a"
              ></u-rate
            ></view>
            <view class=""
              >事业学业:
              <u-rate
                :count="count"
                :modelValue="starsigndata.fortune.work"
                readonly
                active-color="#ffca2a"
              ></u-rate
            ></view>
            <view class=""
              >财富运势:
              <u-rate
                :count="count"
                :modelValue="starsigndata.fortune.money"
                readonly
                active-color="#ffca2a"
              ></u-rate
            ></view>
          </view>
        </view>
      </view>
      <view class="card-t">
        <view class="card-t-l">
          健康指数:
          <text>{{ starsigndata.index.health }}</text>
        </view>
        <view class="card-t-l">
          爱情指数: <text>{{ starsigndata.index.love }}</text>
        </view>
        <view class="card-t-l">
          幸运颜色:
          <text>{{
            starsigndata.luckycolor ? starsigndata.luckycolor : '无'
          }}</text>
        </view>
        <view class="card-t-l">
          幸运数字:
          <text>{{
            starsigndata.luckynumber ? starsigndata.luckynumber : '无'
          }}</text>
        </view>
        <view class="card-t-l">
          速配星座:
          <text>{{
            starsigndata.luckyconstellation
              ? starsigndata.luckyconstellation
              : '无'
          }}</text>
        </view>
        <view class="card-t-l">
          短评: <text>{{ starsigndata.shortcomment }}</text>
        </view>
      </view>
    </view>

    <view class="tag">
      <view
        :class="tagIndex == index ? 'average' : ''"
        v-for="(item, index) in sort"
        :key="index"
        @click="cutSort(index, item.time)"
      >
        {{ item.title }}
      </view>
    </view>
    <view class="details">
      <view class="content">
        <view class="flex-align tag tag-1">
          <u-icon name="star-fill" color="#ffffff" size="18"></u-icon>
          综合运势</view
        >
        <text>{{ starsigndata.fortunetext.all }}</text>
      </view>
      <view class="content">
        <view class="flex-align tag tag-2">
          <u-icon name="heart-fill" color="#ffffff" size="18"></u-icon>
          爱情运势</view
        >
        <text>{{ starsigndata.fortunetext.love }}</text>
      </view>
      <view class="content">
        <view class="flex-align tag tag-3">
          <u-icon name="integral-fill" color="#ffffff" size="18"></u-icon>
          学业事业</view
        >
        <text>{{ starsigndata.fortunetext.work }}</text>
      </view>
      <view class="content">
        <view class="flex-align tag tag-4">
          <u-icon name="red-packet-fill" color="#ffffff" size="18"></u-icon>
          财富运势</view
        >
        <text>{{ starsigndata.fortunetext.money }}</text>
      </view>
      <view class="content">
        <view class="flex-align tag tag-5">
          <u-icon name="level" color="#ffffff" size="18"></u-icon>
          健康运势</view
        >
        <text>{{ starsigndata.fortunetext.health }}</text>
      </view>
    </view>
    <!-- 加载动画组件 -->
    <w-loading mask="true" click="true" ref="loading"></w-loading>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { thirdApi } from '@/request/thirdApi.js'
import { useCounterStore } from '@/store/counter.js'
const store = useCounterStore()
const starsigndata = ref({})
const count = ref(5)
const type = ref('')
const imgUrl = ref('')
const sort = ref([
  {
    title: '今日运势',
    time: 'today'
  },
  {
    title: '明日运势',
    time: 'nextday'
  },
  {
    title: '本周运势',
    time: 'week'
  },
  {
    title: '本月运势',
    time: 'month'
  }
])
const tagIndex = ref(0)
const sortTime = ref('today')
onLoad((option) => {
  type.value = option.type
  imgUrl.value = option.img
})
onShow(() => {
  getData()
})
async function getData() {
  const res = await thirdApi.getFortune({
    type: type.value,
    time: sortTime.value
  })
  starsigndata.value = res.data
  store.showLoading = false
}
async function cutSort(index, time) {
  store.showLoading = true
  tagIndex.value = index
  sortTime.value = time
  getData()
}
</script>

<style lang="scss" scoped>
.card_xingzuo {
  width: 100%;
  height: 100vh;
  padding: 20rpx 28rpx;
  box-sizing: border-box;
  background-color: #f8f8f8;
  padding-bottom: 40rpx;
  .box {
    background-image: url('https://www.xzw.com/static/public/images/fortune/care_bg.jpg');
    background-size: 100% 100%;
    border-radius: 20rpx;
    width: 100%;
    padding: 10rpx 18rpx;
    box-sizing: border-box;
    .card {
      image {
        width: 200rpx;
        height: 200rpx;
        border-radius: 50%;
      }
      .card-r {
        margin-left: 40rpx;
        flex: 1;
        .txt {
          text {
            color: #fff;
            font-weight: bold;
            font-size: 28rpx;
          }
          view {
            color: #fff;
            font-size: 24rpx;
            padding: 2rpx 10rpx;
            background-color: #f3b1c8;
            border-radius: 10rpx;
            margin-left: 10px;
          }
        }
        .exponent {
          margin-top: 10rpx;
          display: flex;
          justify-content: space-between;
          flex-wrap: wrap;

          view {
            color: #dbecf7;
            font-size: 24rpx;
            display: flex;
            align-items: center;
          }
        }
      }
    }
    .card-t {
      margin-top: 20rpx;
      display: flex;
      flex-wrap: wrap;
      .card-t-l {
        color: #dbecf7;
        font-size: 24rpx;
        margin-right: 20rpx;
        margin-bottom: 20rpx;
        text {
          color: #ffca2a;
        }
      }
    }
  }
  .tag {
    margin-top: 20rpx;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    view {
      background-color: #ffffff;
      border-radius: 10rpx;
      padding: 8rpx 20rpx;
      color: #1f1e1e;
      font-size: 24rpx;
    }
    .average {
      background-color: #55a7dc;
      color: #fff;
    }
  }
  .details {
    margin-top: 20rpx;
    background-color: #fff;
    border-radius: 10rpx;
    .content {
      padding: 20rpx 20rpx;
      .tag {
        width: 140rpx;
        font-size: 24rpx;
        padding: 2rpx 10rpx;
        color: #fff;
        font-weight: bold;
        text-align: center;
        border-radius: 10rpx;
        margin-left: 4rpx;
        margin-bottom: 20rpx;
        user-select: text;
      }
      .tag-1 {
        background-color: #80bee4;
      }
      .tag-2 {
        background-color: #ea749e;
      }
      .tag-3 {
        background-color: #ab92dc;
      }
      .tag-4 {
        background-color: #f39f5b;
      }
      .tag-5 {
        background-color: #7fbe58;
      }
      text {
        font-size: 28rpx;
        color: #515151;
        line-height: 40rpx;
      }
    }
  }
}
</style>
